static double utm_northing, utm_easting, utm_zone = 0;
static char utm_zonec;
static UrlLink* link_;
+static gpsbabel_optional::optional<bool> lat_dir_positive;
+static gpsbabel_optional::optional<bool> lon_dir_positive;
#endif // CSVFMTS_ENABLED
/*****************************************************************************/
static void
xcsv_parse_val(const char* s, Waypoint* wpt, const field_map& fmp,
- route_head** trk)
+ route_head** trk, const int line_no)
{
const char* enclosure = "";
geocache_data* gc_data = nullptr;
break;
/* DIRECTIONS **********************************************************/
case XT_LAT_DIR:
- /* latitude N/S. Ignore on input for now */
+ /* latitude N/S. */
+ if (*s == 'n' || *s == 'N') {
+ lat_dir_positive = true;
+ } else if (*s == 's' || *s == 'S') {
+ lat_dir_positive = false;
+ } else {
+ warning("parse of string '%s' on line number %d as LAT_DIR failed. Expected 'n', 'N', 's' or 'S'.\n", s, line_no);
+ }
break;
case XT_LON_DIR:
- /* longitude E/W. Ingore on input for now */
+ /* longitude E/W. */
+ if (*s == 'e' || *s == 'E') {
+ lon_dir_positive = true;
+ } else if (*s == 'w' || *s == 'W') {
+ lon_dir_positive = false;
+ } else {
+ warning("parse of string '%s' on line number %d as LON_DIR failed. Expected 'e', 'E', 'w' or 'W'.\n", s, line_no);
+ }
break;
/* SPECIAL COORDINATES/GRID */
case XT_MAP_EN_BNG:
fatal(MYNAME ": attempt to read, but style '%s' has no IFIELDs in it.\n", CSTR(xcsv_file.description)? CSTR(xcsv_file.description) : "unknown");
}
+ lat_dir_positive.reset();
+ lon_dir_positive.reset();
int ifield_idx = 0;
/* now rip the line apart, advancing the queue for each tear
*/
while (s) {
const field_map& fmp = xcsv_file.ifields.at(ifield_idx++);
- xcsv_parse_val(s, wpt_tmp, fmp, &trk);
+ xcsv_parse_val(s, wpt_tmp, fmp, &trk, linecount);
if (ifield_idx >= xcsv_file.ifields.size()) {
/* we've wrapped the queue. so stop parsing! */
CSTR(xcsv_file.field_encloser), linecount);
}
+ // If XT_LAT_DIR(XT_LON_DIR) was an input field, and the latitude(longitude) is positive,
+ // assume the latitude(longitude) was the absolute value and take the sign from XT_LAT_DIR(XT_LON_DIR).
+ if (lat_dir_positive.has_value() && !lat_dir_positive.value() && (wpt_tmp->latitude > 0.0)) {
+ wpt_tmp->latitude = -wpt_tmp->latitude;
+ }
+ if (lon_dir_positive.has_value() && !lon_dir_positive.value() && (wpt_tmp->longitude > 0.0)) {
+ wpt_tmp->longitude = -wpt_tmp->longitude;
+ }
+
if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) {
double alt;
GPS_Math_Known_Datum_To_WGS84_M(wpt_tmp->latitude, wpt_tmp->longitude, 0.0,